//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Data;
using CommunityServer.Components;

namespace CommunityServer.Discussions.Components
{
	/// <summary>
	/// Summary description for ForumApplication.
	/// </summary>
	public class ForumApplication : CSApplicationData
	{
		public ForumApplication()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        public override string Home
        {
            get{ return Globals.GetSiteUrls().ForumsHome;}
        }

        public override string SectionUrl(IContent ic)
        {
            if(ic != null)
            {
                IndexPost ip = ic as IndexPost;
                if(ip != null)
                    return ForumUrls.Instance().Forum(ip.SectionID);

                ForumPost fp = ic as ForumPost;
                if(fp != null)
                    return ForumUrls.Instance().Forum(fp.SectionID);

                
            }

            return string.Empty;
        }

		public override string PostName
		{
			get
			{
				return ResourceManager.GetString("ForumApplication_Post");
			}
		}

		public override string SectionName
		{
			get
			{
				return ResourceManager.GetString("ForumApplication_Section");
			}
		}

		public override string GroupName
		{
			get
			{
				return ResourceManager.GetString("ForumApplication_Group");
			}
		}

		public override string CategoryName
		{
			get
			{
				return ResourceManager.GetString("ForumApplication_Category");
			}
		}

		#region Favorite Text

		public override string AddFavoritePostText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Forum_AddPost");
			}
		}

		public override string RemoveFavoritePostText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Forum_RemovePost");
			}
		}

		public override string AddFavoriteSectionText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Forum_AddSection");
			}
		}

		public override string RemoveFavoriteSectionText
		{
			get
			{
				return ResourceManager.GetString("Favorites_Forum_RemoveSection");
			}
		}

		#endregion

	    public override IList Groups()
	    {
	        return ForumGroups.GetForumGroups(true,false,false);
	    }

	    public override IList Sections()
	    {
			return Forums.GetForums(false, true, false, false);
	    }

	    public override IList SectionsByGroup(int groupID)
	    {
	        return Forums.GetForumsByForumGroupID(groupID);
	    }

	    public override ApplicationType ApplicationType
	    {
	        get { return ApplicationType.Forum; }
	    }

	    public override string Name
	    {
	        get { return ResourceManager.GetString("forums"); }
	    }

	    public override string Url(Post post)
	    {
	        return ForumUrls.Instance().PostSingle(post.PostID);
	    }

	    public override Post InstantiatePost(IDataReader dr)
	    {
	        return CommunityServer.Discussions.Components.ForumDataProvider.PopulatePostFromIDataReader(dr);
	    }

		public override Post GetPost(int postID)
		{
			return Posts.GetPost(postID, CSContext.Current.User.UserID);
		}

        public override bool Enabled
        {
            get { return ForumConfiguration.Instance().Enabled;}
        }

        public override void SetEnabledStatus(bool enabled)
        {
            ForumConfiguration config = ForumConfiguration.Instance(false);
            config.Enabled = enabled;
            config.Save();
            
        }

		public override bool SupportsTags
		{
			get
			{
				return ForumConfiguration.Instance().EnableTagging;
			}
		}


	}
}
